/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.fatec.main;

import br.fatec.aluno.Aluno;
import br.fatec.aluno.Avaliacao;
import br.fatec.aluno.Disciplina;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.EntityTransaction;
import javax.persistence.Persistence;

/**
 *
 * @author Kenji
 */

public class MainAdicionarAluno {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        EntityManagerFactory fabricaMotores = Persistence.createEntityManagerFactory("escolaModelo");
        
        EntityManager motor = fabricaMotores.createEntityManager();
        
        EntityTransaction transacao = motor.getTransaction();
        
        transacao.begin();
        
        Aluno aluno = new Aluno();
        aluno.setRa(1430001111);
        aluno.setIdade(20);
        aluno.setNome("Caio");
        
        Avaliacao avaliacao = new Avaliacao();
        avaliacao.setId(1);
        avaliacao.setMateria("PPI");
        avaliacao.setNota(5.0);
        
        motor.persist(aluno);
        
        avaliacao.setAluno(aluno);
        
        motor.persist(avaliacao);
        
        Disciplina disciplina = new Disciplina();
        disciplina.setNome("Programaçao");
        disciplina.setNotaMinima(7);
        disciplina.setCodigo("PPI");
        
        disciplina.getAlunos().add(aluno);
        
        motor.persist(disciplina);
        
        transacao.commit();
    }

}
